
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>政策维护</title>
    <script src="../../../res/js/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet" href="../../../res/layui/css/pulas.css" media="all">
    <link rel="stylesheet" href="../../../res/layui/css/layui.css   " media="all">
</head>
<body>

<style>
    .laytable-cell-1-0-3 {
        width: 170px;
        font-family: fantasy;
        color: salmon;
    }
    .laytable-cell-1-0-6 {
        width: 170px;
        font-family: fantasy;
        color: blue;
    }
</style>
<div class="demoTable">

    <input type="hidden" name="informId" id="informId" >

    <div class="layui-inline">
        <input class="labtna" name="materialName" id="materialName" autocomplete="off" placeholder="输入政策名称">
    </div>

    <input type="hidden" id="materialId" name="materialId">

    <div class="layui-inline layui-form">
        <select name="typeId" id="typeId"  class="labtna"  lay-filter="brickType">
            <option value="">
                选择公司名称
            </option>
        </select>
    </div>

    <button type="button" class="layui-btn" data-type="add" id="materialsAdd">
        <i class="layui-icon">&#xe608;</i> 发布
    </button>


</div>
<table class="layui-hide" id="materials" lay-filter="demo"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" id="imgUpdate">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/javascript" src="../../../res/js/base.js"></script>
<script src="../../../res/layui/layui.js"></script>
<script>

    layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
        var laydate = layui.laydate //日期
            ,laypage = layui.laypage //分页
             layer = layui.layer //弹层
            ,table = layui.table //表格
            ,upload = layui.upload //上传
            ,form=layui.form
            ,element = layui.element; //元素操作
        //监听Tab切换
        element.on('tab(demo)', function(data){
            layer.msg('切换了：'+ this.innerHTML);
            console.log(data);
        });

        //执行一个 table 实例
        table.render({
            elem: '#materials'
            ,height: 490
            ,url: '/inform/selectAll' //数据接口
            ,page: true //开启分页
            ,method:'post'
            ,cols: [[ //表头
                {field: 'informContent', title: '政策内容', width:170}
                ,{field: 'informName', title: '政策名称', width:170}
                ,{field: 'oper', title: '操作人', width:170}
                ,{field: 'immName', title: '公司名称', width:170}
                ,{field: 'remark', title: '备注', width:170}
                ,{field: 'informTime', title: '发布时间', width:170}
                ,{fixed: 'right',title: '操作', width: 210, align:'center', toolbar: '#barDemo'}
            ]]
            ,id: 'testReload'
            , done: function (res, curr, count) {
                if (curr > 1 && res.data.length === 0) {
                    curr = curr - 1;
                    table.reload('test', {
                        page: {
                            curr: curr
                        },
                        where: {
                        },
                    });
                }
            }
        });

        //监听工具条
        table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'del'){
                var matId=data.informId;
                layer.confirm('确认删除？', function(index){
                    layer.close(index);
                    var url = "/inform/delect";
                    var data={id:matId};
                    $.post(url,data,function(mes){
                        layer.msg(mes.message);
                        table.reload("testReload");
                    },"json");
                });
            } else if(layEvent === 'edit'){
                layer.open({
                    type: 	2,
                    area : ['80%' , '85%'],//弹出框大小
                    shift:1,//弹出框动画效果
                    content: ["maintenances.html?informId="+data.informId,'on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            }
        });
        //条件查询
        var $ = layui.$;
        $('.demoTable .layui-btn').on('click', function(){
            var materialName = $('#materialName');
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    materialName: materialName.val()
                }
            });
        });
        $('#materialsAdd').on('click', function(){
            layer.open({
                type: 	2,
                area : ['80%' , '85%'],//弹出框大小
                shift:1,//弹出框动画效果
                content: ['maintenances.html','on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            });
        });


        form.on('select(brickType)', function(data) {
            var val= data.elem[data.elem.selectedIndex].text;
            if(val=="选择公司名称"){
                val="";
            }
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    immName: val
                }
            });
        });
        $(function () {
            $('#materialName').bind('input propertychange', function() {
                var materialName = $('#materialName');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        materialName: materialName.val()
                    }
                });
            });
            url = "/inform/queryAll";
            data = null;
            $.get(url,data,function (obj) {
                $.each(obj,function(index,item){
                    $("#typeId").append("<option value="+item.immId+"> "+item.immName+"</option>");
                })
                //重新渲染
                form.render('select');
            },"json");

            var T;
            $(".latn").onmouseover=function(){
                T=setInterval("fmouseOver()", 500);
            }
            $(".latn").onmouseout=function(){
                clearInterval(t);
            }
        })
    });
</script>
</body>
</html>